package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KClassCategory;
import com.ruoyi.qsng.service.IKClassCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程班级分类Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/category")
@Api(tags = "pc--课程班级分类Controller")
public class KClassCategoryController extends BaseController {
    @Autowired
    private IKClassCategoryService kClassCategoryService;

    /**
     * 查询课程班级分类列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:category:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询课程班级分类列表")
    public TableDataInfo list(KClassCategory kClassCategory) {
        startPage();
        List<KClassCategory> list = kClassCategoryService.selectKClassCategoryList(kClassCategory);
        return getDataTable(list);
    }

    /**
     * 查询课程班级分类列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:category:list')")
    @GetMapping("/listNotLimit")
    @ApiOperation(value = "查询课程班级分类列表")
    public AjaxResult listNotLimit(KClassCategory kClassCategory) {
        List<KClassCategory> list = kClassCategoryService.selectKClassCategoryList(kClassCategory);
        return success(list);
    }

    /**
     * 导出课程班级分类列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:category:export')")
    @Log(title = "课程班级分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出课程班级分类列表")
    public void export(HttpServletResponse response, KClassCategory kClassCategory) {
        List<KClassCategory> list = kClassCategoryService.selectKClassCategoryList(kClassCategory);
        ExcelUtil<KClassCategory> util = new ExcelUtil<KClassCategory>(KClassCategory.class);
        util.exportExcel(response, list, "课程班级分类数据");
    }

    /**
     * 获取课程班级分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:category:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取课程班级分类详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kClassCategoryService.selectKClassCategoryById(id));
    }

    /**
     * 新增课程班级分类
     */
    @PreAuthorize("@ss.hasPermi('qsng:category:add')")
    @Log(title = "课程班级分类", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增课程班级分类")
    public AjaxResult add(@RequestBody KClassCategory kClassCategory) {
        return toAjax(kClassCategoryService.insertKClassCategory(kClassCategory));
    }

    /**
     * 修改课程班级分类
     */
    @PreAuthorize("@ss.hasPermi('qsng:category:edit')")
    @Log(title = "课程班级分类", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改课程班级分类")
    public AjaxResult edit(@RequestBody KClassCategory kClassCategory) {
        return toAjax(kClassCategoryService.updateKClassCategory(kClassCategory));
    }

    /**
     * 删除课程班级分类
     */
    @PreAuthorize("@ss.hasPermi('qsng:category:remove')")
    @Log(title = "课程班级分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除课程班级分类")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kClassCategoryService.deleteKClassCategoryByIds(ids));
    }
}
